package com.vmix.vmixmobiledemo;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

/**
 * Videos Tab Activity
 * 
 * @author lei
 *
 */
public class VideosTabActivity extends TabActivity {
	
	// tab hosts
	private TabHost tabHost = null;
	
	// private collection id
	private String collectionId = null;
	
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        
		setDefaultKeyMode( Activity.DEFAULT_KEYS_SEARCH_LOCAL );

        // window features
        requestWindowFeature( Window.FEATURE_INDETERMINATE_PROGRESS );
        
        setContentView(R.layout.main);
        
		// get the intent used to launch this activity
		Intent intent = getIntent();
		// retrieve the saved collectionId
		Bundle bundle = intent.getExtras();
		this.collectionId = bundle.getString( "collectionId" );
    
        // initialize tabset
        this.initializeTabs();

	}
	
    
	/**
	 * @see android.app.Activity#onDestroy()
	 */
    @Override
    public void onDestroy()
    {
    	super.onDestroy();

    }
	
    /**
     * initialize the tabset on main activity
     * 
     */
    private void initializeTabs()
    {
    	
    	if( this.tabHost != null ) {
    		throw new IllegalStateException("Trying to intialize already initializd TabHost");
    	}
    	
    	Resources res = getResources();
    	
    	this.tabHost = getTabHost();	// get tabhost
    	TabHost.TabSpec tabSpec = null;	// initialize tab spec
    	Intent tabIntent = null; 		// define tab intent
    	
    	View tab1 = LayoutInflater.from(this).inflate(R.layout.vmix_tab_layout, null);
        ImageView iv = (ImageView) tab1.findViewById(R.id.vmixTabImageView);
        iv.setImageResource(R.drawable.lookup_icon_gray_48);
        TextView tv = (TextView) tab1.findViewById(R.id.vmixTabTextView);
        tv.setText("Browse");
        
    	View tab2 = LayoutInflater.from(this).inflate(R.layout.vmix_tab_layout, null);
        ImageView iv2 = (ImageView) tab2.findViewById(R.id.vmixTabImageView);
        iv2.setImageResource(R.drawable.upload_icon_gray_48);
        TextView tv2 = (TextView) tab2.findViewById(R.id.vmixTabTextView);
        tv2.setText("Upload");
    
    	// Create an intent for the collections activity
    	tabIntent = new Intent().setClass(this, BrowseVideosActivity.class );
    	// add the collectionId here as well
    	tabIntent.putExtra("collectionId", this.collectionId );
    	
    	
    	
    	tabSpec = tabHost.newTabSpec("browse").setIndicator(tab1).setContent(tabIntent);
    	tabHost.addTab(tabSpec);
    	
    	// Create an intent for the upload activity
    	tabIntent = new Intent().setClass(this, UploadActivity.class ); 
    	
    	// add the collectionId here as well
    	tabIntent.putExtra("collectionId", this.collectionId );
    	tabSpec = tabHost.newTabSpec("upload").setIndicator(tab2).setContent(tabIntent);
    	tabHost.addTab(tabSpec);
    
    	// set current tab
    	tabHost.setCurrentTab(0);
    	
    }
}
